package threadTest;

public class ThreadTest {
    public static void main(String[] args) {
        Tiger tiger = new Tiger();
        ThreadProxy threadProxy =new ThreadProxy(tiger);
        threadProxy.start();
        for (int i = 0; i < 10;i++){
            System.out.println("我是线程："+ Thread.currentThread().getName());
        }
    }
}

// 自己用代码实现一个简单的静态代理模式，实现Runnable接口达到实现多线程的目的

// 测试类,Tiger类已经继承了Animal类，所以不能继承Thread类实现多线程，所以通过实现Runnable接口实现多线程
class Animal{}
class Tiger extends Animal implements Runnable{

    private int times =0;

    @Override
    public void run() {
        while (true){
            System.out.println("我是线程："+ Thread.currentThread().getName()+ " " +(++times));
            if (times == 10){
                break;
            }
        }
    }
}

// 自己实现的简单线程代理类
class ThreadProxy implements Runnable{
    private Runnable target = null;

    public ThreadProxy(Runnable target){
        this.target = target;
    }

    public void run(){
        if (target != null){
            target.run();
        }
    }

    public void start(){
        start0();
    }

    public void start0(){
        run();
    }
}
